package com.yonyou.crm.sys.modules.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonyou.crm.common.biz.service.BaseBizServiceImpl;
import com.yonyou.crm.common.field.handler.FieldRelationHandler;
import com.yonyou.crm.common.field.relation.FieldRelation;
import com.yonyou.crm.common.field.relation.RefFieldRelation;
import com.yonyou.crm.sys.modules.entity.BiztypeRoleVO;
import com.yonyou.crm.sys.org.service.SysOrgBizServiceImpl;

@Service
public class BiztypeRoleBizServiceImpl extends BaseBizServiceImpl<BiztypeRoleVO>{
	
	@Autowired
	private SysOrgBizServiceImpl orgService;
	
	public List<BiztypeRoleVO> getAssignRoles(Map<String, Object> param){
		List<BiztypeRoleVO> biztypeRoleList = dao.selectVoList(BiztypeRoleVO.class, "getAssignRoles", param);
		return transBiztypeRoles(biztypeRoleList);
	}
	
	private List<BiztypeRoleVO> transBiztypeRoles(List<BiztypeRoleVO> biztypeRoles){
		if(biztypeRoles != null && biztypeRoles.size() > 0) {
			List<FieldRelation<BiztypeRoleVO>> relations = new ArrayList<FieldRelation<BiztypeRoleVO>>();
			relations.add(new RefFieldRelation<BiztypeRoleVO>(BiztypeRoleVO.class, "orgId", new String[]{"orgName"}, orgService, "selectFieldsByIds"));
			new FieldRelationHandler<BiztypeRoleVO>().handler(biztypeRoles, relations);
		}
		return biztypeRoles;
	}
}
